<template>
  <div>
    <el-upload
      ref="avatarUpload"
      class="avatar-uploader"
      :headers="headers"
      :action="common_upload"
      :show-file-list="false"
      :on-success="handlePhotoSuccess">
      <img v-if="value" :src="value" class="avatar">
      <i v-else class="el-icon-plus avatar-uploader-icon"></i>
    </el-upload>
  </div>
</template>

<script>
import {getToken} from "@/utils/auth";

export default {
  props: {
    value: String,
  },
  data() {
    return {
      headers: {
        Authorization: "Bearer " + getToken(),
      },
    };
  },
  methods:{
    handlePhotoSuccess(response, file, fileList){
      this.$emit("input", response.msg);
      this.$refs.avatarUpload.clearFiles();
    }
  }
};
</script>
<style scoped lang="scss">
::v-deep.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
::v-deep.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
::v-deep.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
::v-deep.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>

